# encoding  :  utf-8 _*_
# @author   :  朱清闯
# @software :  PyCharm
# time      :  2022/3/19 14:36
msg_dict = {500: '服务器内部错误', 200: '操作成功', 201: '部分成功', 401: '未授权或认证失败', 403: '禁止访问！', 404: "未找到文件",
            405: "请求不允许!", 409: "扩展名错误", 419: "未登录！", 406: '表单未通过',
            1001: '帐号不能为空', 1002: '密码不能为空', 1003: '帐号或者密码错误', 1004: '手机号码不合法', 1005:
                '手机号码为空', 1006: '手机号码已经被注册', 1007: '发送时间不足1分钟',
            1008: '该姓名已经被注册', 1009: "手机号码和姓名都已经被注册", 1010: '验证码不能为空',
            1011: '验证码错误', 1012: "查询的条件错误", 1013: "请携带正确的token", 1099: "查询结果为空", 1014: "重复的记录",
            1015: "非正常渠道获取手机验证码", 1016: "实名认证，不能空！", 1017: "验证码过期了", 1018: "手机短信息发送不足1分钟",
            1019: "该手机没有发送过验证码", 1020: "前端缺乏随机号码", 1021: "记录已经存在", 1022: "没必要的操作",
            1023: "用户未激活，请联系管理员", 1024: "审核状态为拒绝", 1025: '密码不允许修改'
            }


# 根据result的内容再封装成data:{count,results}的格式，最终的格式为{success,total,code,message,data:{count,results}}
def error_result(code=1099, results='', msg='', total=0):
    data = {'count': 0, 'results': ''}
    if code == 200:
        response = {'success': True}
    else:
        response = {'success': False}
    if isinstance(results, list):
        count = len(results)
        data['count'] = count
    elif isinstance(results, dict) or isinstance(results, str):
        count = 1
        data['count'] = count
    data['results'] = results
    data['total'] = total
    response['total'] = total
    response['code'] = code
    if msg == '':
        response['message'] = msg_dict[code]
    else:
        response['message'] = msg
    response['data'] = data
    return response
